package com.huawei.gamebox.service.welfare.gift.card;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.n;
import androidx.recyclerview.widget.RecyclerView.s;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.gamebox.service.common.cardkit.card.BaseGsCard;
import com.huawei.gamebox.service.welfare.gift.bean.GameGiftHorizonScrollCardBean;
import o.azb;
import o.cgz;
import o.chy;
import o.ContentManager;
import o.eix;
import o.eiy;
import o.epv;
import o.MinimumFactory;
import o.exp$a;
import o.exp$b;
import o.exp.d;
import o.exp.j;
import o.fcg;

public class GameGiftHorizonScrollCard extends BaseGiftCard {
    private LinearLayoutManager ʼ;
    private chy ˊ;
    private eix ˋ = new eix();
    private RecyclerView ˎ;
    public GameGiftHorizonScrollCardBean ˏ = null;
    private a ᐝ;

    class a extends androidx.recyclerview.widget.RecyclerView.a<b> {
        final /* synthetic */ GameGiftHorizonScrollCard ˎ;

        class b extends s {
            private GameGiftCard ʻॱ = null;
            final /* synthetic */ a ॱˋ;
            private View ॱᐝ;

            public b(a aVar, View view) {
                this.ॱˋ = aVar;
                super(view);
                this.ʻॱ = new GameGiftCard(view.getContext());
                this.ʻॱ.ˊ(view);
                this.ʻॱ.ˉ().setClickable(true);
                this.ॱᐝ = view;
                this.ʻॱ.ॱ(aVar.ˎ.ʻ());
            }
        }

        private a(GameGiftHorizonScrollCard gameGiftHorizonScrollCard) {
            this.ˎ = gameGiftHorizonScrollCard;
        }

        @NonNull
        public /* synthetic */ s ˎ(@NonNull ViewGroup viewGroup, int i) {
            return ॱ(viewGroup, i);
        }

        public /* synthetic */ void ॱ(@NonNull s sVar, int i) {
            ˏ((b) sVar, i);
        }

        @NonNull
        public b ॱ(@NonNull ViewGroup viewGroup, int i) {
            return new b(this, LayoutInflater.from(viewGroup.getContext()).inflate(j.ˍ, viewGroup, false));
        }

        public void ˏ(@NonNull b bVar, int i) {
            GameGiftHorizonScrollCardBean gameGiftHorizonScrollCardBean = (GameGiftHorizonScrollCardBean) this.ˎ.ˊᐝ;
            ((CardBean) gameGiftHorizonScrollCardBean.ˊ().get(i)).ˋˋ(gameGiftHorizonScrollCardBean.ॱˉ());
            bVar.ʻॱ.ˏ((CardBean) gameGiftHorizonScrollCardBean.ˊ().get(i));
            MarginLayoutParams marginLayoutParams = (MarginLayoutParams) bVar.ॱᐝ.getLayoutParams();
            if (marginLayoutParams != null) {
                if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
                    ˊ(i, marginLayoutParams);
                } else {
                    ˎ(i, marginLayoutParams);
                }
                bVar.ॱᐝ.setLayoutParams(marginLayoutParams);
            }
        }

        private void ˎ(int i, MarginLayoutParams marginLayoutParams) {
            marginLayoutParams.setMarginEnd(0);
            if (i == 0) {
                marginLayoutParams.setMarginStart(this.ˎ.ˋ.ॱ());
                return;
            }
            if (i == ˏ() - 1) {
                marginLayoutParams.setMarginEnd(this.ˎ.ˋ.ॱ());
            }
            marginLayoutParams.setMarginStart(this.ˎ.ˋ.ॱॱ());
        }

        private void ˊ(int i, MarginLayoutParams marginLayoutParams) {
            marginLayoutParams.setMarginStart(0);
            if (i == 0) {
                marginLayoutParams.setMarginEnd(this.ˎ.ˋ.ॱ());
                return;
            }
            if (i == ˏ() - 1) {
                marginLayoutParams.setMarginStart(this.ˎ.ˋ.ॱ());
            }
            marginLayoutParams.setMarginEnd(this.ˎ.ˋ.ॱॱ());
        }

        public int ˏ() {
            if (this.ˎ.ˏ == null || this.ˎ.ˏ.ˊ() == null) {
                return 0;
            }
            return this.ˎ.ˏ.ˊ().size();
        }
    }

    public /* synthetic */ cgz ˏ(View view) {
        return ˊ(view);
    }

    public GameGiftHorizonScrollCard(Context context) {
        super(context);
        this.ˋ.ॱ(context.getResources().getDimensionPixelSize(exp$a.ॱ));
        this.ˋ.ˏ(context.getResources().getDimensionPixelSize(exp$a.ॱ));
        this.ˋ.ˋ(context.getResources().getInteger(exp$b.ˎ));
        this.ˋ.ʼ(context.getResources().getInteger(exp$b.ˏ));
        this.ˋ.ˊ(epv.ˊ());
        this.ˋ.ˎ(azb.ˊ(this.ॱ));
        this.ˋ.ᐝ(epv.ॱॱ());
    }

    public BaseGsCard ˊ(View view) {
        ʽ(view);
        ˊ((RecyclerView) view.findViewById(d.ˋ));
        this.ᐝ = new a();
        this.ʼ = new LinearLayoutManager(view.getContext(), 0, false);
        ˊ().setLayoutManager(this.ʼ);
        if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
            ˊ().setLayoutDirection(0);
            this.ʼ.ˊ(true);
        }
        ˊ().setAdapter(this.ᐝ);
        new eiy().ˏ(ˊ());
        this.ˎ.ॱ(new n(this) {
            final /* synthetic */ GameGiftHorizonScrollCard ˎ;

            {
                this.ˎ = r1;
            }

            public void ˎ(RecyclerView recyclerView, int i) {
                if (i == 0) {
                    GameGiftHorizonScrollCardBean gameGiftHorizonScrollCardBean = (GameGiftHorizonScrollCardBean) this.ˎ.ˌ();
                    Object obj = this.ˎ.ʼ.ॱˎ() == this.ˎ.ʼ.ˌ() + -1 ? 1 : null;
                    int ॱˎ = this.ˎ.ʼ.ॱˎ();
                    this.ˎ.ˋ.ॱॱ(this.ˎ.ʼ.ॱˊ());
                    this.ˎ.ˋ.ʻ(this.ˎ.ˊ().getLeft());
                    if (obj != null) {
                        gameGiftHorizonScrollCardBean.ॱ(ॱˎ);
                        gameGiftHorizonScrollCardBean.ˎ(this.ˎ.ˋ.ʻ());
                        return;
                    }
                    gameGiftHorizonScrollCardBean.ˎ(this.ˎ.ˋ.ʻ());
                    gameGiftHorizonScrollCardBean.ॱ(this.ˎ.ˋ.ᐝ());
                }
            }
        });
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof GameGiftHorizonScrollCardBean) {
            this.ˏ = (GameGiftHorizonScrollCardBean) cardBean;
            this.ʼ.ॱ(this.ˏ.ᐝ(), this.ˏ.ˋॱ());
            if (this.ˏ.ʼ() <= 0) {
                this.ˏ.ˊ(new fcg(this.ˋ).ˏ(this.ॱ, this.ˏ.ˊ()));
            }
            LayoutParams layoutParams = this.ˎ.getLayoutParams();
            layoutParams.height = this.ˏ.ʼ();
            this.ˎ.setLayoutParams(layoutParams);
            this.ᐝ.ˊ();
        }
    }

    public RecyclerView ˊ() {
        return this.ˎ;
    }

    public void ˊ(RecyclerView recyclerView) {
        this.ˎ = recyclerView;
    }

    public chy ʻ() {
        return this.ˊ;
    }

    public void ॱ(chy o_chy) {
        this.ˊ = o_chy;
    }
}
